package com.taro.blog.service;

import com.taro.blog.dao.ArticleDao;
import com.taro.blog.model.ArticleDetailResult;
import com.taro.blog.model.ArticleListResult;
import com.taro.blog.model.User;

public class ArticleService {
    public ArticleListResult articleList(User currentUser) {
        ArticleDao articleDao = new ArticleDao();
        ArticleListResult result = new ArticleListResult();

        result.currentUser = currentUser;
        if (currentUser != null) {
            result.articleCount = articleDao.selectArticleCountByUid(currentUser.uid);
            result.typeCount = articleDao.selectTypeCountByUid(currentUser.uid);
            result.articleList = articleDao.selectListByUid(currentUser.uid);
        }

        return result;
    }

    public ArticleDetailResult detail(User currentUser, int aid) {
        ArticleDetailResult result = new ArticleDetailResult();
        if (currentUser == null) {
            return result;
        }

        // currentUser
        result.currentUser = currentUser;

        ArticleDao articleDao = new ArticleDao();

        // articleCount
        result.articleCount = articleDao.selectArticleCountByUid(currentUser.uid);
        // typeCount
        result.typeCount = articleDao.selectTypeCountByUid(currentUser.uid);
        // article
        result.article = articleDao.selectOneByAid(aid);

        return result;
    }
}
